﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using KLY.DataModels;
using KLY.Tools;

namespace KLY.ServiceCore
{
    public class RegisterAccount : ServiceBase<RegisterReuest, RegisterResponse>
    {
        public RegisterAccount(RegisterReuest request)
        {
            this._request = request;
        }

        public override RegisterResponse Process()
        {
            this._request.Platform = "003";
            if(!Validate())
            {
                return new RegisterResponse
                {
                    Ok = false,
                    Message = "注册信息不正确，请确认短信验证码是否填写？密码是否大于6位？手机号码是否正确？"
                };
            }
            base.Url = string.Format("http://{0}/v1/api/101001/", BizCommon.Domain);
            base.Method = HttpMethod.POST;
            base.ListHead = new List<RequestHead>
                {
                    new RequestHead
                    {
                        HeaderName="version",
                        HeaderValue="1.0.0"
                    }
                };
            base.Request = this._request;
            var result = base.Process();
            if(result==null)
            {
                return new RegisterResponse
                {
                    Ok = false,
                    Message = "注册失败，请稍微再试！"
                };
            }
            return result;
        }

        private bool Validate()
        {
            if(!BizCommon.CheckIsValidateMobilePhone(this._request.Phone))
            {
                return false;
            }

            if(string.IsNullOrWhiteSpace(this._request.Verify_Code) || this._request.Verify_Code.Length!=6)
            {
                return false;
            }

            if (string.IsNullOrWhiteSpace(this._request.Password) || this._request.Password.Length < 6)
            {
                return false;
            }
            return true;
        }
        private RegisterReuest _request;
    }
}
